<?php
if (!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
    exit('Access Denied');
}
require './source/plugin/csdn123com_kuaibao/common.fun.php';
$server_url = 'action=plugins&operation=config&do=' . $pluginid . '&identifier=csdn123com_kuaibao&pmod=now';
if ($_GET['formhash'] == FORMHASH && empty($_GET['search']) == false) {
    if (empty($_GET['keyword'])) {
        cpmsg('csdn123com_kuaibao:keyword_empty', '', 'error');
    }
    $keyword = $_GET['keyword'];
    $rndpage = $_GET['rndpage'];
    $fid = $_GET['fid'];
    $threadtypeid = $_GET['threadtypeid'];
    $uidstr = $_GET['uidstr'];
    $keyword = diconv($keyword, CHARSET, 'UTF-8');
    $dataCatchUrl = kuaibaoKeyword($keyword);
    $htmlcode = dfsockopen($dataCatchUrl);
    if (strlen($htmlcode) < 200) {
        $htmlcode = dfsockopen($dataCatchUrl, 0, '', '', FALSE, '', 15, TRUE, 'URLENCODE', FALSE);
    }
    $htmlcode = base64_encode($htmlcode);
    $htmlcode = dfsockopen('http://discuz.csdn123.net/catch/kuaibao/now.catch.php', 0, array('htmlcode' => $htmlcode));
    $htmlcode = preg_replace('/^\s+|\s+$/', '', $htmlcode);
    $htmlcode = base64_decode($htmlcode);
    $linkArr = dunserialize($htmlcode);
    if (is_array($linkArr) == true && count($linkArr) > 0) {
        foreach ($linkArr as $linkValue) {
            $chk = DB::fetch_first("SELECT ID FROM " . DB::table('csdn123kuaibao_news') . " WHERE fromurl='" . daddslashes($linkValue['href']) . "'  LIMIT 1");
            if (empty($chk)) {
                $linkValue['text'] = diconv($linkValue['text'],'UTF-8');
                $insertData = array();
                $insertData['fromurl'] = $linkValue['href'];
                $insertData['subject'] = $linkValue['text'];
                $insertData['uidstr'] = $uidstr;
                $insertData['fid'] = $fid;
                $insertData['typeid'] = $threadtypeid;
                DB::insert('csdn123kuaibao_news', $insertData);
            }
        }
        $now_catch_ok_url = 'action=plugins&operation=config&do=' . $pluginid . '&identifier=csdn123com_kuaibao&pmod=send';
        cpmsg('csdn123com_kuaibao:now_catch_ok', $now_catch_ok_url, 'succeed');
    } else {
        cpmsg('csdn123com_kuaibao:linkarr_err', '', 'error');
    }
} else {
	
	require_once libfile('function/forumlist');
	include template("csdn123com_kuaibao:now");

}